﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LevelEditor.Objects.Layers
{
    public class Layer : List<Tile>
    {
        private int layerIndex;
        public int LayerIndex
        {
            get { return layerIndex; }
            set 
            { 
                layerIndex = value;
                SetIndex(layerIndex);
            }
        }

        private bool isVisible;
        public bool Visible
        {
            get { return isVisible; }
            set
            {
                isVisible = value;
                ChangeVisibility();
            }
        }

        private LevelEditor levelEditor;        
        
        public Layer(LevelEditor levelEditor) : base()
        {
            this.levelEditor = levelEditor;
            isVisible = true;
            
        }

        /// <summary>
        /// The 0 value send the item to back. 
        /// The number of controls in the form is the max index
        /// </summary>
        /// <param name="index"></param>
        private void SetIndex(int index)
        {
            for (int k = 0; k < Count; k++)
            {
                if (!levelEditor.stage1.Controls.Contains(this[k])) continue;

                levelEditor.stage1.Controls.SetChildIndex(this[k], index);
            }
        }


        private void ChangeVisibility()
        {
            for (int k = 0; k < this.Count; k++)
            {
                this[k].Visible = !this[k].Visible;
            }
        }
        
    }
}
